package com.zego.wawaji.ui.center.transport.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.zego.wawaji.base.data.BaseData;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 物流列表
 */
public class StepList extends BaseData implements Parcelable {
    private List<StepItemData> stepList = new ArrayList<>();
    private String expTextName;   // 快递公司
    private String mailNo;        // 物流单号

    @Override
    public void parseJson(String jsonStr) {
        JSONObject jsonObject = getJsonObject(jsonStr);

        if (jsonObject.isNull("showapi_res_body")) return;

        JSONObject bodyObject = getJsonObject(jsonObject.optString("showapi_res_body"));
        if (!bodyObject.isNull("data")) {
            JSONArray jsonArray = getJsonArray(bodyObject.optString("data"));
            this.stepList = (List<StepItemData>) getBaseDataList(jsonArray, StepItemData.class);
        }

        this.expTextName = bodyObject.optString("expTextName");
        this.mailNo = bodyObject.optString("mailNo");
    }

    public String getExpTextName() {
        return expTextName;
    }

    public String getMailNo() {
        return mailNo;
    }

    public List<StepItemData> getStepList() {
        return stepList;
    }

    public StepList() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeTypedList(this.stepList);
        dest.writeString(this.expTextName);
        dest.writeString(this.mailNo);
    }

    protected StepList(Parcel in) {
        this.stepList = in.createTypedArrayList(StepItemData.CREATOR);
        this.expTextName = in.readString();
        this.mailNo = in.readString();
    }

    public static final Creator<StepList> CREATOR = new Creator<StepList>() {
        @Override
        public StepList createFromParcel(Parcel source) {
            return new StepList(source);
        }

        @Override
        public StepList[] newArray(int size) {
            return new StepList[size];
        }
    };
}
